/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Inloggen.java
 *
 * Created on 25-jan-2011, 14:04:22
 */
package nl.maxato.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableColumn;

import nl.maxato.controller.Controller;
import nl.maxato.domain.Athlete;
import nl.maxato.modellen.AtleetTableModel;
import nl.maxato.util.ConfigurationFile;
import nl.maxato.util.ParameterNames;
import nl.maxato.xmlservices.ConvertXMLData;
import nl.maxato.xmlservices.XMLService;

/**
 *
 * @author Danny
 */
public class CalculateDisciplineGUI extends javax.swing.JFrame {

    XMLService xmlService;
    ResourceBundle rb;
    Controller controller;
    List<Athlete> adf;
    String language;
    String country;
    Locale locale;
    ConfigurationFile cf;

    /** Creates new form berekenOnderdeel */
    public CalculateDisciplineGUI() {
        controller = new Controller();
        xmlService = XMLService.getInstance();
        adf = xmlService.xmlToAthletes();

        //initComponents();
        makeComponents();
        cf = new ConfigurationFile();
        translateGUI(controller.getLanguague(cf.getLanguage()));
    }

    private void jButton_Calculate_SkillsActionPerformed(java.awt.event.ActionEvent evt) {
        try {

            
            adf = xmlService.xmlToAthletes();
            List<Athlete> athlesSkillList = new ArrayList<Athlete>();
            athlesSkillList = controller.calculateDiscipline(adf, jComboBox_Discipline.getSelectedIndex(), jComboBox_Specialty.getSelectedIndex(), jComboBox_Sex.getSelectedIndex(), jCheckBox_form.isSelected(), jCheckBox_care.isSelected(), jCheckBox_experience.isSelected());
            if (!athlesSkillList.isEmpty()) {
                AtleetTableModel atm = new AtleetTableModel(athlesSkillList);
                atm.setColumnNames(rb.getString("NAME"), rb.getString("MAXID"), rb.getString("FORM"), rb.getString("CARE"), rb.getString("MOOD"), rb.getString("EXPERIENCE"), rb.getString("STRENGHT"), rb.getString("STAMINA"), rb.getString("SPEED"), rb.getString("AGILITY"), rb.getString("JUMP"), rb.getString("THROWING"), rb.getString("SPEC1"), rb.getString("SPEC2"), rb.getString("VALUE"));
                jTable_Athletes.setModel(atm);
                jTable_Athletes.setAutoCreateRowSorter(true);
                jTable_Athletes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                TableColumn column = jTable_Athletes.getColumnModel().getColumn(0);
                column.setPreferredWidth(130);
                for (int i = 1; i < 5; i++) {
                    column = jTable_Athletes.getColumnModel().getColumn(i);
                    column.setPreferredWidth(50);
                }
                for (int w = 5; w < 14; w++) {
                    column = jTable_Athletes.getColumnModel().getColumn(w);
                    column.setPreferredWidth(70);
                }
                for (int y = 12; y < 14; y++) {
                    column = jTable_Athletes.getColumnModel().getColumn(y);
                    column.setPreferredWidth(50);
                }
                column = jTable_Athletes.getColumnModel().getColumn(14);
                column.setPreferredWidth(50);
                if (athlesSkillList.isEmpty()) {
                    jTable_Athletes.setVisible(false);
                }
                jTable_Athletes.setVisible(true);
            } else {
                jTable_Athletes.setVisible(false);
            }
        } catch (Exception e) {
            System.out.println(e);
            jTable_Athletes.setVisible(false);
        }
    }

    public final void translateGUI(ResourceBundle b) {
        rb = b;
        
        this.setTitle(b.getString("MAXATO_CALCULATE_DISCIPLINES"));
        jLabel_Discipline.setText(b.getString("DISCIPLINE") + ":");
        jLabel_Specialty.setText(b.getString("SPECIALTY") + ":");
        jLabel_Sex.setText(b.getString("SEX") + ":");
        jButton_Calculate_Skills.setText(b.getString("CALCULATE"));
        
        jLabel_Form.setText(b.getString("FORM"));
        jLabel_Care.setText(b.getString("CARE"));
        jLabel_Experience.setText(b.getString("EXPERIENCE"));

        jMenu_File.setText(b.getString("FILE"));
        jMenu_Languague.setText(b.getString("LANGUAGE"));

        jMenuItem_Close.setText(b.getString("CLOSE"));
    
        jMenuItem_English.setText(ParameterNames.languageENGLISH);
        jMenuItem_Dutch.setText(ParameterNames.languageDUTCH);
        jMenuItem_Polish.setText(ParameterNames.languagePOLISH);
        jMenuItem_Deutsch.setText(ParameterNames.languageDEUTSCH);
        jMenuItem_Francais.setText(ParameterNames.languageFRANCAIS);
        jMenuItem_Espanol.setText(ParameterNames.languageESPANOL);
        jMenuItem_Portuguese.setText(ParameterNames.languagePORTUGUESE);
        jMenuItem_Czech.setText(ParameterNames.languageCZECH);
        jMenuItem_Greek.setText(ParameterNames.languageGREEK);
        jMenuItem_Italian.setText(ParameterNames.languageITALIAN);
        jMenuItem_Estonian.setText(ParameterNames.languageESTONIAN);
        jMenuItem_Russian.setText(ParameterNames.languageRUSSIAN);
        jMenuItem_Hungarian.setText(ParameterNames.languageHungarian);


        JComboBox cb = jComboBox_Discipline;

        cb.removeAllItems();
        cb.insertItemAt(b.getString("100METERS"), 0);
        cb.insertItemAt(b.getString("200METERS"), 1);
        cb.insertItemAt(b.getString("400METERS"), 2);
        cb.insertItemAt(b.getString("110METERHURDLES"), 3);
        cb.insertItemAt(b.getString("400METERHURDLES"), 4);
        cb.insertItemAt(b.getString("800METERS"), 5);
        cb.insertItemAt(b.getString("1500METERS"), 6);
        cb.insertItemAt(b.getString("3000STEEPLECHASE"), 7);
        cb.insertItemAt(b.getString("5000METERS"), 8);
        cb.insertItemAt(b.getString("10000METERS"), 9);
        cb.insertItemAt(b.getString("MARATHON"), 10);
        cb.insertItemAt(b.getString("10KMRACEWALK"), 11);
        cb.insertItemAt(b.getString("20KMRACEWALK"), 12);
        cb.insertItemAt(b.getString("50KMRACEWALK"), 13);
        cb.insertItemAt(b.getString("HIGHJUMP"), 14);
        cb.insertItemAt(b.getString("POLEVAULT"), 15);
        cb.insertItemAt(b.getString("LONGJUMP"), 16);
        cb.insertItemAt(b.getString("TRIPLEJUMP"), 17);
        cb.insertItemAt(b.getString("SHOTPUT"), 18);
        cb.insertItemAt(b.getString("DISCUSTHROW"), 19);
        cb.insertItemAt(b.getString("HAMMERTHROW"), 20);
        cb.insertItemAt(b.getString("JAVELINTHROW"), 21);
        cb.insertItemAt(b.getString("RELAYS4X100"), 22);
        cb.insertItemAt(b.getString("RELAYS4X400"), 23);
        cb.setSelectedIndex(0);

        JComboBox cbb = jComboBox_Specialty;
        cbb.removeAllItems();
        cbb.insertItemAt(b.getString("ALL_ATHLETES"), 0);
        cbb.insertItemAt(b.getString("NO_SPECIALTY"), 1);
        cbb.insertItemAt(b.getString("SPRINTERS"), 2);
        cbb.insertItemAt(b.getString("MIDDLE_DISTANCE_RUNNERS"), 3);
        cbb.insertItemAt(b.getString("LONG_DISTANCE_RUNNERS"), 4);
        cbb.insertItemAt(b.getString("RACE_WALKERS"), 5);
        cbb.insertItemAt(b.getString("JUMPERS"), 6);
        cbb.insertItemAt(b.getString("THROWERS"), 7);
        cbb.setSelectedIndex(0);

        JComboBox cbbb = jComboBox_Sex;
        cbbb.removeAllItems();
        cbbb.insertItemAt(b.getString("BOTH"), 0);
        cbbb.insertItemAt(b.getString("MEN"), 1);
        cbbb.insertItemAt(b.getString("WOMEN"), 2);
        cbbb.setSelectedIndex(0);
        jButton_Calculate_SkillsActionPerformed(null);
    }

    private void jMenuItem_EnglishActionPerformed(java.awt.event.ActionEvent evt) {
        translateGUI(controller.getLanguague("en"));
    }

    private void jMenuItem_DutchActionPerformed(java.awt.event.ActionEvent evt) {
        translateGUI(controller.getLanguague("nl"));
    }

    private void jMenuItem_ITALIANActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("it"));
    }

    private void jMenuItem_GREEKActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("el"));
    }

    private void jMenuItem_CZECHActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("cs"));
    }

    private void jMenuItem_PolishActionPerformed(java.awt.event.ActionEvent evt) {
        translateGUI(controller.getLanguague("pl"));
    }

    private void jMenuItem_PortugueseActionPerformed(java.awt.event.ActionEvent evt) {
        translateGUI(controller.getLanguague("pt"));
    }

    private void jMenuItem_DEUTSCHActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("de"));
    }

    private void jMenuItem_FRANCAISActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("fr"));
    }

    private void jMenuItem_ESPANOLActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("es"));
    }

    private void jMenuItem_ESTONIANActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("et"));
    }

    private void jMenuItem_RUSSIANActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("ru"));
    }

    private void jMenuItem_HUNGARIANActionPerformed(ActionEvent evt) {
        translateGUI(controller.getLanguague("hu"));
    }
    
    private void jMenuItem_AfsluitenActionPerformed(java.awt.event.ActionEvent evt) {
        this.dispose();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
//zet de GUI om in Windows-look
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception e) {
            System.out.println("Unable to load Windows look and feel");
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                // new BerekenOnderdeelGUI().setVisible(true);
            }
        });
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        //  java.net.URL imgURL = path;
        if (path != null) {
            return new ImageIcon(path);
        } else {
            System.err.println("Couldn't find image file: " + path);
            return null;
        }
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton_Calculate_Skills;
    private javax.swing.JComboBox jComboBox_Specialty;
    private javax.swing.JComboBox jComboBox_Discipline;
    private javax.swing.JComboBox jComboBox_Sex;
    private javax.swing.JLabel jLabel_Discipline;
    private javax.swing.JLabel jLabel_Specialty;
    private javax.swing.JLabel jLabel_Sex;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable_Athletes;
        private javax.swing.JMenu jMenu_File;
    private javax.swing.JMenu jMenu_Languague;
    private javax.swing.JMenuBar jMenuBar1;
    JMenuItem jMenuItem_Close;
    JMenuItem jMenuItem_English;
    JMenuItem jMenuItem_Dutch;
    JMenuItem jMenuItem_Polish;
    JMenuItem jMenuItem_Deutsch;
    JMenuItem jMenuItem_Francais;
    JMenuItem jMenuItem_Espanol;
    JMenuItem jMenuItem_Portuguese;
    JMenuItem jMenuItem_Hungarian;
    private javax.swing.JMenuItem jMenuItem_Estonian;
    private javax.swing.JMenuItem jMenuItem_Russian;
    private javax.swing.JMenuItem jMenuItem_Italian;
    private javax.swing.JMenuItem jMenuItem_Czech;
    private javax.swing.JMenuItem jMenuItem_Greek;
    JCheckBox jCheckBox_form;
    JCheckBox jCheckBox_care;
    JCheckBox jCheckBox_experience;
    JLabel jLabel_Form;
    JLabel jLabel_Care;
    JLabel jLabel_Experience;
    // End of variables declaration

    private void makeComponents() {
        //Creating the Frame
        this.setDefaultCloseOperation(CalculateDisciplineGUI.DISPOSE_ON_CLOSE);
        // this.setSize(800, 520);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width - 1005) / 2, (screenSize.height - 553) / 2, 1005, 553);
        setResizable(false);
        //Creating the MenuBar and adding components
        jMenuBar1 = new JMenuBar();
        jMenu_File = new JMenu();
        jMenu_Languague = new JMenu();
        jMenuBar1.add(jMenu_File);
        jMenuBar1.add(jMenu_Languague);
        ImageIcon icon;
        icon = createImageIcon("img/close.png");
        jMenuItem_Close = new JMenuItem(icon);
        jMenuItem_Close.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_AfsluitenActionPerformed(evt);
            }
        });

        icon = createImageIcon("img/gb.png");
        jMenuItem_English = new JMenuItem(icon);
        jMenuItem_English.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_EnglishActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/nl.png");
        jMenuItem_Dutch = new JMenuItem(icon);
        jMenuItem_Dutch.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_DutchActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/pl.png");
        jMenuItem_Polish = new JMenuItem(icon);
        jMenuItem_Polish.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_PolishActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/pt.png");
        jMenuItem_Portuguese = new JMenuItem(icon);
        jMenuItem_Portuguese.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_PortugueseActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/de.png");
        jMenuItem_Deutsch = new JMenuItem(icon);
        jMenuItem_Deutsch.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_DEUTSCHActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/et.png");
        jMenuItem_Estonian = new JMenuItem(icon);
        jMenuItem_Estonian.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_ESTONIANActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/ru.png");
        jMenuItem_Russian = new JMenuItem(icon);
        jMenuItem_Russian.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_RUSSIANActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/fr.png");
        jMenuItem_Francais = new JMenuItem(icon);
        jMenuItem_Francais.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_FRANCAISActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/es.png");
        jMenuItem_Espanol = new JMenuItem(icon);
        jMenuItem_Espanol.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_ESPANOLActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/hu.png");
        jMenuItem_Hungarian = new JMenuItem(icon);
        jMenuItem_Hungarian.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_HUNGARIANActionPerformed(evt);
            }
        });        
        icon = createImageIcon("img/gr.png");
        jMenuItem_Greek = new JMenuItem(icon);
        jMenuItem_Greek.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_GREEKActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/cz.png");
        jMenuItem_Czech = new JMenuItem(icon);
        jMenuItem_Czech.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_CZECHActionPerformed(evt);
            }
        });
        icon = createImageIcon("img/it.png");
        jMenuItem_Italian = new JMenuItem(icon);
        jMenuItem_Italian.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_ITALIANActionPerformed(evt);
            }
        });
        jMenu_File.add(jMenuItem_Close);
        jMenu_Languague.add(jMenuItem_Czech);
        jMenu_Languague.add(jMenuItem_Deutsch);
        jMenu_Languague.add(jMenuItem_Estonian);
        jMenu_Languague.add(jMenuItem_English);
        jMenu_Languague.add(jMenuItem_Greek);
        jMenu_Languague.add(jMenuItem_Espanol);
        jMenu_Languague.add(jMenuItem_Francais);
        jMenu_Languague.add(jMenuItem_Hungarian);
        jMenu_Languague.add(jMenuItem_Italian);
        jMenu_Languague.add(jMenuItem_Dutch);
        jMenu_Languague.add(jMenuItem_Polish);
        jMenu_Languague.add(jMenuItem_Portuguese);
        jMenu_Languague.add(jMenuItem_Russian);

        //Panel for Center North
        JPanel panels = new JPanel(); // the panel is not visible in output
        jLabel_Discipline = new JLabel();
        jComboBox_Discipline = new JComboBox();
        jLabel_Specialty = new JLabel();
        jComboBox_Specialty = new JComboBox();
        jLabel_Sex = new JLabel();
        jComboBox_Sex = new JComboBox();
        jButton_Calculate_Skills = new JButton();
        jButton_Calculate_Skills.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_Calculate_SkillsActionPerformed(evt);
            }
        });
        panels.add(jLabel_Discipline);// Components Added using Flow Layout
        panels.add(jComboBox_Discipline);
        panels.add(jLabel_Specialty);
        panels.add(jComboBox_Specialty);
        panels.add(jLabel_Sex);
        panels.add(jComboBox_Sex);
        

        //Panel for Center Center
        jTable_Athletes = new JTable();
        jTable_Athletes.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{}));
        jScrollPane1 = new JScrollPane();
        jScrollPane1.setViewportView(jTable_Athletes);
//jScrollPane1.setSize(new Dimension(1005, 475));
        JPanel iets = new JPanel();
        jCheckBox_form = new JCheckBox();
        jCheckBox_form.setSelected(true);
        jLabel_Form = new JLabel();
        jCheckBox_care = new JCheckBox();
        jCheckBox_care.setSelected(true);
        jLabel_Care = new JLabel();
        jCheckBox_experience = new JCheckBox();
        jCheckBox_experience.setSelected(true);
        jLabel_Experience = new JLabel();
        

        iets.add(jCheckBox_form);
        iets.add(jLabel_Form);
        iets.add(jCheckBox_care);
        iets.add(jLabel_Care);
        iets.add(jCheckBox_experience);
        iets.add(jLabel_Experience);
        iets.add(jButton_Calculate_Skills);

        //Create Center Panel
        JPanel p1 = new JPanel();
        //p1.setSize(1005, 75);
        p1.setLayout(new BorderLayout());
        p1.add(panels, BorderLayout.NORTH);
        p1.add(iets, BorderLayout.CENTER);
        //  p1.add(jScrollPane1, BorderLayout.SOUTH);

        //Add panels to GUI
        this.getContentPane().add(BorderLayout.NORTH, jMenuBar1);
        this.getContentPane().add(BorderLayout.CENTER, p1);
        this.getContentPane().add(BorderLayout.SOUTH, jScrollPane1);
        this.setVisible(true);
    }
}
